﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{ 
    public class DSTWBQILISTData : BaseFunction
    { 
        public string WBBSTKNR = "", WBBART = "", WBBWAKZ = "", WBBFARBE = "", WBBBESCHICH = "", WBBVAR = "", WBBISTKLG = "", WBBSGEW = "", WBBAUFTYP = "", WBBAUFKRS = "", WBBAUFLFD = "", WBBAUFPOS = "";
        public DSTWBQILISTData()
            : base()
        {

        }
        public DSTWBQILISTData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public DSTWBQILISTData(OracleConnection _myConnection, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_myConnection, _proxy, userID)
        {
           
        }
        /// <summary>
        /// 根据布卷编号获取他本身的品种信息。和当前的品种信息进行比对，如果不同，则将该品种所有的布卷读取出来。 
        ///  </summary>
        /// <param name="WBBSTKNR"></param>
        /// <returns></returns>
        public DataSet GetWBBST(string wkdate)
        {
            string TableName = "WBBST";
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal = null;
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT F.WBEWMNRKRS,F.WBEWMLFDNR, F.WBEWMPOS,F.WBEWBUCHDAT,F.WBEWBUCHBEN"
                    +" ,FB.WBBART,FB.WBBFARBE,FB.WBBBESCHICH,FB.WBBVAR,FB.WBBDPART,FB.WBBISTKLG,FB.WBBSBRT,FB.WBBIBRT,"
                    +" F.WBEWBELEG,F.WBEWLFDNR,FB.WBBBEM,F.WBEWSTKNR,RB.WBBSTKNR AS RSTKNR,RB.WBBISTKLG AS RSTKLG,"
                    + " F.WBEWLO,F.WBEWLB,F.WBEWLP,FB.WBBRWKRS,FB.WBBRWLFD,FB.WBBPOS,'' AS COMMENTS"
                    +" FROM WBBEW F"
                    +"  JOIN WBBST FB ON FB.WBBSTKNR=F.WBEWSTKNR"
                    +" LEFT JOIN WBBST RB ON   RB.WBBSTKNR=F.WBEWTSTKNR"
                    + " WHERE F.wbewfc='QI04    ' AND F.WBEWLFDNR=1 AND WBEWBUCHDAT=:WBEWBUCHDAT ";
                orlReadCommand.Parameters.Add("WBEWBUCHDAT", OracleType.NVarChar).Value = wkdate;
                //WBBBESCHICH
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = TableName;
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = TableName;
                }
                foreach (DataRow dwTmp in tableLocal.Rows)
                {
                    //  '0002300038                                                '
                    string TXTISIND = dwTmp["WBBRWKRS"].ToString() + dwTmp["WBBRWLFD"].ToString() + dwTmp["WBBPOS"].ToString();
                    dwTmp["COMMENTS"] = GetCommentsFromTXTIND("WBS", TXTISIND);
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetWBFEHL(string wkdate)
        {
            string TableName = "WBFEHL";
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataTable tableLocal = null;
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT F.WBEWMNRKRS,F.WBEWMLFDNR, F.WBEWMPOS,"
                + "WBEWBUCHDAT,WBEWBUCHBEN,WBBSTKNR,FB.WBBWAKZ,FB.WBBART,FB.WBBFARBE,FB.WBBBESCHICH,FB.WBBVAR,WBBISTKLG"
                + ",WBFFSCHL,SUBSTR(SDDATEN,2,8) AS CDES,substr(sddaten,52,10) as CVALUE,Round(WBFLGVON*0.001,0) as WBFLGVON,Round(WBFLGBIS*0.001,0) AS WBFLGBIS"
                    +"  from WBBEW F JOIN WBBST FB ON  WBBSTKNR=WBEWSTKNR"
                    +"  LEFT JOIN WBFEHL ON FB.WBBRWKRS=WBFRWKRS AND FB.WBBRWLFD=WBFRWLFD AND FB.WBBPOS=WBFRWPOS"
                    +"    LEFT JOIN SDDAT ON  SDSA='0267' AND WBFMANDANT||WBFFSCHL=SDKEY"
                    + " WHERE F.wbewfc='QI04    ' AND F.WBEWLFDNR=1 AND WBEWBUCHDAT=:WBEWBUCHDAT ";
                orlReadCommand.Parameters.Add("WBEWBUCHDAT", OracleType.NVarChar).Value = wkdate;
                //WBBBESCHICH
                setResult = Connect2Proxy(orlReadCommand);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = TableName;
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = TableName;
                } 
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }   

    }
}